import App from './App.vue'
import router from './router/index'
import store from './store'
import ZkTable from 'vue-table-with-tree-grid'
const Vue = require('vue')
const axios = require('axios')
const NProgress = require('nprogress')
// 阻止 vue 在启动时生成生产提示
Vue.config.productionTip = false
Vue.prototype.$http = axios
// 设置axios默认路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
// 处理时间的过滤器
Vue.filter('formatData', function (data) {
  const formatData = new Date(data)
  const year = formatData.getFullYear()
  const month = formatData.getMonth() + 1
  const day = formatData.getDate()
  const hours = formatData.getHours()
  const minutes = formatData.getMinutes()
  const seconds = formatData.getSeconds()
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
})
// 添加请求拦截器，携带token
axios.interceptors.request.use(function (config) {
  // 在请求拦截器中引入进度条开始
  NProgress.start()
  const token = window.sessionStorage.getItem('token')
  config.headers.Authorization = token
  return config
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error)
})
// 添加响应拦截器
axios.interceptors.response.use(function (config) {
  // 在响应拦截器中引入进度条结束
  NProgress.done()
  return config
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error)
})
// Vue.use(VueQuillEditor)
Vue.component('tree-table', ZkTable)
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
